//
//  RootLeftViewController.m
//  片刻
//
//  Created by lanou3g on 15/6/2.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RootLeftViewController.h"
#import "RootRightViewController.h"
#import "ClassNameModel.h"
#import "MainListBaseViewController.h"
@interface RootLeftViewController ()

//创建右侧的试图控制器
@property (nonatomic,retain) RootRightViewController *rootRinghVC;
//左侧的控制器列表
@property (nonatomic,retain) UITableView *mainListTableView;
//存放和提供tableView数据和将要跳转的界面
@property (nonatomic,retain) NSMutableArray *dataSourceArr;

@end

@implementation RootLeftViewController

-(void)dealloc
{
    self.rootRinghVC = nil;
    self.mainListTableView = nil;
    self.dataSourceArr = nil;
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createDataSourceArr]; //创建数组提供tableView数据和将要跳转的界面
    [self createMainListTableView]; //创建tableView
    [self createImage];
    [self createButton];
    [self createPlayer];
    
    [self createRightView]; //创建右试图放在左试图上面
    self.view.backgroundColor = [UIColor grayColor];
    [self.mainListTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"aaa"]; //注册
    
}
//创建头像
-(void)createImage
{
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 60, 60)];
    image.backgroundColor = [UIColor yellowColor];
    image.layer.cornerRadius = 30;
    image.layer.masksToBounds = YES;
    [self.view addSubview:image];
}
//创建 button
-(void)createButton
{
//    登入
    UIButton *LoginButon = [UIButton buttonWithType:(UIButtonTypeSystem)];
    LoginButon.frame = CGRectMake(84, 40, 30, 30);
    [LoginButon setTitle:@"登入" forState:(UIControlStateNormal)];
    [LoginButon addTarget:self action:@selector(clickLoginButton:) forControlEvents:(UIControlEventTouchUpInside)];
//    LoginButon.backgroundColor = [UIColor yellowColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(123, 32, 15, 44)];
    label.text = @"|";
//    注册
    UIButton *registeredButon = [UIButton buttonWithType:(UIButtonTypeSystem)];
    registeredButon.frame = CGRectMake(135, 40, 30, 30);
    [registeredButon setTitle:@"注册" forState:(UIControlStateNormal)];
    [registeredButon addTarget:self action:@selector(clickRegisteredButton:) forControlEvents:(UIControlEventTouchUpInside)];
//    registeredButon.backgroundColor = [UIColor yellowColor];
//    缓存
    UIButton *DownloadButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    DownloadButton.frame = CGRectMake(25, 96, 20, 20);
    [DownloadButton addTarget:self action:@selector(clickDownloadButton:) forControlEvents:(UIControlEventTouchUpInside)];
    DownloadButton.backgroundColor = [UIColor yellowColor];
//    喜欢
    UIButton *likeButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    likeButton.frame = CGRectMake(84, 96, 20, 20);
    [likeButton addTarget:self action:@selector(clickLikeButton:) forControlEvents:(UIControlEventTouchUpInside)];
    likeButton.backgroundColor = [UIColor yellowColor];
//    消息
    UIButton *infoButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    infoButton.frame = CGRectMake(145, 96, 20, 20);
    [infoButton addTarget:self action:@selector(clickInfoButton:) forControlEvents:(UIControlEventTouchUpInside)];
    infoButton.backgroundColor = [UIColor yellowColor];
//    编辑
    UIButton *editButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    editButton.frame = CGRectMake(208, 96, 20, 20);
    [editButton addTarget:self action:@selector(clickEditButton:) forControlEvents:(UIControlEventTouchUpInside)];
    editButton.backgroundColor = [UIColor yellowColor];
//    搜索
    UIButton *searchButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    searchButton.frame = CGRectMake(25, 124, 203, 30);
    [searchButton addTarget:self action:@selector(clickSearchButton:) forControlEvents:(UIControlEventTouchUpInside)];
    searchButton.backgroundColor = [UIColor yellowColor];
    
    [self.view addSubview:LoginButon];
    [self.view addSubview:registeredButon];
    [self.view addSubview:DownloadButton];
    [self.view addSubview:likeButton];
    [self.view addSubview:infoButton];
    [self.view addSubview:editButton];
    [self.view addSubview:label];
    [self.view addSubview:searchButton];
}

-(void)createPlayer
{
    UIView *prlayer = [[UIView alloc] initWithFrame:CGRectMake(0, 590, 272, 50)];
    prlayer.backgroundColor = [UIColor grayColor];
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(5, 4, 40, 40)];
    image.backgroundColor = [UIColor yellowColor];
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(50, 4, 152, 21)];
    UILabel *name1= [[UILabel alloc] initWithFrame:CGRectMake(50, 25, 152, 21)];
    name.backgroundColor = [UIColor brownColor];
    name1.backgroundColor = [UIColor blueColor];
    name.text = @"音乐作者";
    name1.text = @"音乐名";
//    播放
    UIButton *Button = [UIButton buttonWithType:(UIButtonTypeSystem)];
    Button.frame = CGRectMake(222, 8, 30, 30);
    [Button setTitle:@"播放" forState:(UIControlStateNormal)];
    [Button addTarget:self action:@selector(clickSearchButton:) forControlEvents:(UIControlEventTouchUpInside)];
    Button.backgroundColor = [UIColor yellowColor];
    
    [prlayer addSubview:name];
    [prlayer addSubview:name1];
    [prlayer addSubview:image];
    [prlayer addSubview:Button];
    [self.view addSubview:prlayer];
}

//登入点击事件
-(void)clickLoginButton:(UIButton *)button
{
   
}
//注册点击事件
-(void)clickRegisteredButton:(UIButton *)button
{
    NSLog(@"sadf");
}
//缓存点击事件
-(void)clickDownloadButton:(UIButton *)button
{
    
}
//喜欢点击事件
-(void)clickLikeButton:(UIButton *)button
{
    
}
//消息点击事件
-(void)clickInfoButton:(UIButton *)button
{
    
}
//编辑点击事件
-(void)clickEditButton:(UIButton *)button
{
    
}
//搜索点击事件
-(void)clickSearchButton:(UIButton *)button
{
    
}

//创建数组方法
-(void)createDataSourceArr
{
//    @[@"辅助",@"AuxiliaryViewController"]
    self.dataSourceArr = [NSMutableArray array]; //初始化
//    用二维数组来存放数据
    NSArray *arr = @[@[@"首页",@"HomeViewController"],@[@"电台",@"RadioViewController"],@[@"阅读",@"ReadViewController"],@[@"社区",@"CommunityViewController"],@[@"碎片",@"DebrisViewController"],@[@"良品",@"ProductViewController"],@[@"设置",@"SetupViewController"]];
//    遍历二维数组 得到数组里面数组 然后放进 dataSourceArr 里面
    for (NSArray *modelArr in arr) {
        ClassNameModel *model = [[ClassNameModel alloc] init];
        model.disName = modelArr[0];
        model.className = modelArr[1];
        [self.dataSourceArr addObject:model];
    }
}

//创建一个tableView方法
-(void)createMainListTableView{
    self.mainListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 220, 270, 300) style:(UITableViewStylePlain)];
    self.mainListTableView.backgroundColor = [UIColor grayColor];
    self.mainListTableView.dataSource = self; //接受协议
    self.mainListTableView.delegate = self; //接受协议
    [self.view addSubview:_mainListTableView];
    [_mainListTableView release];
}
#pragma mark - dataSource的方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSourceArr.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ClassNameModel *model = self.dataSourceArr[indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"aaa" forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%@",model.disName];
    cell.backgroundColor = [UIColor grayColor];
    return cell;
}

#pragma mark - delegate协议的方法  点击下标做出反应
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ClassNameModel *model = self.dataSourceArr[indexPath.row];
    [self.rootRinghVC addViewWith:model]; //调用rootRinghVC里面的方法 选中的时候
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

//一. 创建右侧的试图控制器，并把试图添加到左侧试图上
-(void)createRightView{
    self.rootRinghVC = [[RootRightViewController alloc] init];
    [self.view addSubview:self.rootRinghVC.view];
    [self.rootRinghVC release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
